//
//  AppController.m
//  <6.1>RaiseMan
//
//  Created by chen on 16/9/12.
//  Copyright © 2016年 tyrad. All rights reserved.
//

#import "AppController.h"
#import "PreferenceController.h" 

@implementation AppController


//每个类 initialize 先收到消息。 为了保证defaults先注册,可以重载initialize方法 
+ (void)initialize
{
    if (self == [AppController class]) {
        
        NSMutableDictionary *defaultValues = [[NSMutableDictionary alloc]init];
        
        //归档颜色对象
        NSData *colorAsData = [NSKeyedArchiver archivedDataWithRootObject:[NSColor yellowColor]];
        
        [defaultValues setObject:colorAsData forKey:BNRTableBgColorKey];
        [defaultValues setObject:@(YES) forKey:BNREmptyDocKey];
        
        //登记defaults的字典
        [[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
    }
}

- (void)showPreferencePannel:(id)sender{
    
    if (_preferenceController == nil) {
        _preferenceController = [[PreferenceController alloc]init];
    }
    NSLog(@"show: %@",_preferenceController);
    [_preferenceController showWindow:self];
}




- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender{
    return [PreferenceController preferenceEmptyDoc];
}
                     
@end







